import requests
import json

class PatagentClient:
    def __init__(self, api_key=None, url="http://localhost:1888"):
        self.api_key = api_key
        self.url = url

    def invoke(self, params):
        headers = {
            'User-Agent': 'Apipost client Runtime/+https://www.apipost.cn/',
            'Content-Type': 'application/json',
        }
        data = { "input": params }
        response = requests.post(f'{self.url}/invoke', headers=headers, json=data, timeout=300)
        if response.status_code == 200:
            res = json.loads(response.text)
            return res['output']
        else:
            print(f"Error: {response.text}")
